package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.TOrderDetail;
import com.ruoyi.system.mapper.TOrderDetailDao;
import com.ruoyi.system.service.TOrderDetailService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (TOrderDetail)表服务实现类
 *
 * @author makejava
 * @since 2025-01-01 20:37:34
 */
@Service("tOrderDetailService")
public class TOrderDetailServiceImpl implements TOrderDetailService {
    @Resource
    private TOrderDetailDao tOrderDetailDao;


    @Override
    public TOrderDetail queryById(Integer id) {
        return this.tOrderDetailDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param tOrderDetail 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<TOrderDetail> queryByPage(TOrderDetail tOrderDetail, PageRequest pageRequest) {
        long total = this.tOrderDetailDao.count(tOrderDetail);
        return new PageImpl<>(this.tOrderDetailDao.queryAllByLimit(tOrderDetail, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param tOrderDetail 实例对象
     * @return 实例对象
     */
    @Override
    public TOrderDetail insert(TOrderDetail tOrderDetail) {
        this.tOrderDetailDao.insert(tOrderDetail);
        return tOrderDetail;
    }

    /**
     * 修改数据
     *
     * @param tOrderDetail 实例对象
     * @return 实例对象
     */
    @Override
    public TOrderDetail update(TOrderDetail tOrderDetail) {
        this.tOrderDetailDao.update(tOrderDetail);
        return this.queryById(tOrderDetail.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.tOrderDetailDao.deleteById(id) > 0;
    }
}
